# -*- coding: utf-8 -*-

class AdminImagesController < AdminController
  def index
    @image = Image.new
  end
  
  def upload
    up_f = params[:attachment]
    #DB保存
    @image = Image.new(params[:image])
    @image.filename = up_f.original_filename
    #@image.image_data = up_f.read
    @image.save!
    #ファイル保存
    @image.save_to_file(up_f)

    @images = Image.select('id, image_type, maker, production').where(:filename => @image.filename).all
    render :action => :index
  end
  
  def edit
    @image = Image.find(params[:id])
  end
  
  def update
    @image = Image.find(params[:image][:id])
    @image.update_attributes params[:image]
    @image.save!
    
    @images = Image.select('id, image_type, maker, production').where(:filename => @image.filename).all
    render :action => :index
  end
end
